home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / wsanet8a / wsanet / wsmtpc / vb30 / formsmtp.frm next >
Text File  |  1996-04-08  |  15KB  |  512 lines

  1. VERSION 2.00
  2. Begin Form Main 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "SMTP Test Client"
  5.    ClientHeight    =   4260
  6.    ClientLeft      =   1035
  7.    ClientTop       =   1665
  8.    ClientWidth     =   8475
  9.    Height          =   4920
  10.    Icon            =   FORMSMTP.FRX:0000
  11.    Left            =   990
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4260
  14.    ScaleWidth      =   8475
  15.    Top             =   1050
  16.    Width           =   8565
  17.    Begin Ini Ini 
  18.       Left            =   7800
  19.       Top             =   1800
  20.    End
  21.    Begin SSPanel StatusBar 
  22.       Align           =   2  'Align Bottom
  23.       Alignment       =   1  'Left Justify - MIDDLE
  24.       AutoSize        =   3  'AutoSize Child To Panel
  25.       BackColor       =   &H00C0C0C0&
  26.       Caption         =   "Ok."
  27.       Font3D          =   3  'Inset w/light shading
  28.       Height          =   255
  29.       Left            =   0
  30.       TabIndex        =   9
  31.       Top             =   4005
  32.       Width           =   8475
  33.    End
  34.    Begin SSFrame FrameProgress 
  35.       Font3D          =   0  'None
  36.       Height          =   2775
  37.       Left            =   120
  38.       TabIndex        =   6
  39.       Top             =   960
  40.       Width           =   7575
  41.       Begin ListBox ListProgress 
  42.          Height          =   2370
  43.          Left            =   120
  44.          TabIndex        =   7
  45.          Top             =   240
  46.          Width           =   7335
  47.       End
  48.    End
  49.    Begin NetClient NetClient 
  50.       Left            =   7800
  51.       LineDelimiter   =   ""
  52.       RecvSize        =   4096
  53.       RecvThreshold   =   0
  54.       Top             =   1320
  55.    End
  56.    Begin SSPanel PanelLocalName 
  57.       Align           =   1  'Align Top
  58.       Alignment       =   6  'Center - TOP
  59.       BackColor       =   &H00C0C0C0&
  60.       BevelWidth      =   2
  61.       Caption         =   "PanelLocalHost"
  62.       Font3D          =   4  'Inset w/heavy shading
  63.       Height          =   855
  64.       Left            =   0
  65.       MousePointer    =   2  'Cross
  66.       TabIndex        =   0
  67.       Top             =   0
  68.       Width           =   8475
  69.       Begin SSPanel PanelUserName 
  70.          Alignment       =   6  'Center - TOP
  71.          AutoSize        =   3  'AutoSize Child To Panel
  72.          BackColor       =   &H00C0C0C0&
  73.          Font3D          =   1  'Raised w/light shading
  74.          Height          =   255
  75.          Left            =   105
  76.          TabIndex        =   4
  77.          Top             =   480
  78.          Width           =   1620
  79.          Begin TextBox TextUserName 
  80.             BackColor       =   &H00C0C0C0&
  81.             BorderStyle     =   0  'None
  82.             FontBold        =   0   'False
  83.             FontItalic      =   0   'False
  84.             FontName        =   "MS Sans Serif"
  85.             FontSize        =   8.25
  86.             FontStrikethru  =   0   'False
  87.             FontUnderline   =   0   'False
  88.             Height          =   225
  89.             Left            =   15
  90.             MaxLength       =   64
  91.             TabIndex        =   5
  92.             Text            =   "iblenke"
  93.             Top             =   15
  94.             Width           =   1590
  95.          End
  96.       End
  97.       Begin SSPanel PanelHost 
  98.          Alignment       =   6  'Center - TOP
  99.          AutoSize        =   3  'AutoSize Child To Panel
  100.          BackColor       =   &H00C0C0C0&
  101.          Font3D          =   1  'Raised w/light shading
  102.          Height          =   255
  103.          Left            =   2115
  104.          TabIndex        =   2
  105.          Top             =   480
  106.          Width           =   2985
  107.          Begin TextBox TextHost 
  108.             BackColor       =   &H00C0C0C0&
  109.             BorderStyle     =   0  'None
  110.             FontBold        =   0   'False
  111.             FontItalic      =   0   'False
  112.             FontName        =   "MS Sans Serif"
  113.             FontSize        =   8.25
  114.             FontStrikethru  =   0   'False
  115.             FontUnderline   =   0   'False
  116.             Height          =   225
  117.             Left            =   15
  118.             MaxLength       =   128
  119.             TabIndex        =   3
  120.             Text            =   "rhino.ess.harris.com"
  121.             Top             =   15
  122.             Width           =   2955
  123.          End
  124.       End
  125.       Begin Label LabelLocalAddr 
  126.          Alignment       =   2  'Center
  127.          BackStyle       =   0  'Transparent
  128.          Caption         =   "LabelLocalAddr"
  129.          FontBold        =   0   'False
  130.          FontItalic      =   0   'False
  131.          FontName        =   "MS Sans Serif"
  132.          FontSize        =   8.25
  133.          FontStrikethru  =   0   'False
  134.          FontUnderline   =   0   'False
  135.          Height          =   255
  136.          Left            =   120
  137.          TabIndex        =   8
  138.          Top             =   240
  139.          Width           =   8175
  140.       End
  141.       Begin Label LabelAt 
  142.          BackColor       =   &H00C0C0C0&
  143.          Caption         =   "@"
  144.          FontBold        =   0   'False
  145.          FontItalic      =   0   'False
  146.          FontName        =   "MS Sans Serif"
  147.          FontSize        =   12
  148.          FontStrikethru  =   0   'False
  149.          FontUnderline   =   0   'False
  150.          Height          =   375
  151.          Left            =   1785
  152.          TabIndex        =   1
  153.          Top             =   480
  154.          Width           =   375
  155.       End
  156.    End
  157.    Begin Menu MenuAbout 
  158.       Caption         =   "&About"
  159.    End
  160. End
  161. Dim LocalHostName As String
  162. Dim CRLF As String
  163.  
  164. Const STATE_INACTIVE = 0
  165. Const STATE_HELO = 1
  166. Const STATE_VRFY = 2
  167. Const STATE_MAILFROM = 3
  168. Const STATE_RCPTTO = 4
  169. Const STATE_DATA = 5
  170. Const STATE_SENDBODY = 6
  171. Const STATE_QUIT = 7
  172.  
  173. Dim SMTPState As Integer
  174.  
  175. Sub Form_Load ()
  176.     
  177.     If NetClient.HostName = "" Then
  178.         PanelLocalName = "LocalHost"
  179.         PanelLocalAddr = "unknown address"
  180.     Else
  181.         PanelLocalName = NetClient.HostName
  182.         LabelLocalAddr = NetClient.HostAddr
  183.     End If
  184.     
  185.     LocalHostName = PanelLocalName
  186.      
  187.     CRLF = Chr$(13) + Chr$(10)
  188.     NetClient.LineDelimiter = CRLF
  189.     
  190.     ' Use SMTP service (port 25)
  191.     NetClient.RemoteService = "smtp"
  192.     If NetClient.RemotePort = 0 Then
  193.         NetClient.RemotePort = 25
  194.     End If
  195.  
  196.     Ini.Filename = "wsmtpc.ini"
  197.     Ini.Section = "Windows"
  198.     Main.Top = gfMISCIniGetInt("Main.Top", (Main.Top))
  199.     Main.Left = gfMISCIniGetInt("Main.Left", (Main.Left))
  200.     Main.Width = gfMISCIniGetInt("Main.Width", (Main.Width))
  201.     Main.Height = gfMISCIniGetInt("Main.Height", (Main.Height))
  202.     
  203.     Main.Show
  204.  
  205. End Sub
  206.  
  207. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  208.  
  209.     If UnloadMode = 0 Then
  210.         Ini.Section = "Windows"
  211.         gsMISCIniPutInt "Main.Top", (Main.Top)
  212.         gsMISCIniPutInt "Main.Left", (Main.Left)
  213.         gsMISCIniPutInt "Main.Width", (Main.Width)
  214.         gsMISCIniPutInt "Main.Height", (Main.Height)
  215.     End If
  216.  
  217. End Sub
  218.  
  219. Sub Form_Resize ()
  220.  
  221.     If Main.WindowState = 1 Then Exit Sub
  222.     
  223.     LabelLocalAddr.Width = Abs(ScaleWidth - 240)
  224.     PanelHost.Width = Abs(ScaleWidth - PanelHost.Left - 120)
  225.  
  226.     TextHost.Width = Abs(ScaleWidth - TextHost.Left - 120)
  227.  
  228.     FrameProgress.Width = Abs(ScaleWidth - 240)
  229.     FrameProgress.Height = Abs(ScaleHeight - FrameProgress.Top - StatusBar.Height - 120)
  230.     
  231.     ListProgress.Width = Abs(FrameProgress.Width - 240)
  232.     ListProgress.Height = Abs(FrameProgress.Height - 360)
  233.  
  234. End Sub
  235.  
  236. Sub LabelLocalAddr_DblClick ()
  237.     
  238.     PanelLocalName_DblClick
  239.  
  240. End Sub
  241.  
  242. Sub MenuAbout_Click ()
  243.  
  244.     Ini.Section = "Windows"
  245.     gsMISCAboutLoad "About WSMTPC", "WSMTPC v1.1", "This client is merely an example of a state-based application. This program merely sends a single line 'message' to a user on an SMTP host, and shows the SMTP conversation."
  246.  
  247. End Sub
  248.  
  249. Sub NetClient_OnClose ()
  250.     
  251.     On Error Resume Next
  252.  
  253.     SMTPState = STATE_INACTIVE
  254.     
  255.     SMTPCancel
  256.  
  257.     StatusBar.Caption = "Ok."
  258.  
  259. End Sub
  260.  
  261. Sub NetClient_OnConnect ()
  262.  
  263.     On Error Resume Next
  264.     
  265.     StatusBar.Caption = "Connected to " & NetClient.HostName & " - Click this message to Abort."
  266.     
  267.     SMTPState = STATE_HELO
  268.  
  269. End Sub
  270.  
  271. Sub NetClient_OnError (ErrorNumber As Integer)
  272. Dim sTemp As String
  273.  
  274.     On Error Resume Next
  275.  
  276.     ' Can't read past end of connection!
  277.     If ErrorNumber = 10038 Then
  278.         If NetClient.Socket = -1 Then
  279.             Exit Sub
  280.         End If
  281.     End If
  282.     
  283.     sTemp = NetClient.ErrorMessage
  284.     ReportProgress sTemp
  285.     
  286.     SMTPCancel
  287.  
  288. End Sub
  289.  
  290. Sub NetClient_OnRecv ()
  291. Dim sLine As String
  292. Dim iReturn As Integer
  293.  
  294.     On Error Resume Next
  295.  
  296.     Do
  297.         sLine = NetClient.RecvLine
  298.         If sLine = "" Then Exit Do
  299.         ReportProgress ">" + sLine
  300.  
  301.         ' Handle SMTP multi-line responses
  302.         While Mid$(sLine, 4, 1) = "-"
  303.             sLine = NetClient.RecvLine
  304.         Wend
  305.  
  306.         SMTPParse sLine
  307.         DoEvents
  308.     Loop While NetClient.RecvCount > 0
  309.     
  310. End Sub
  311.  
  312. Sub PanelLocalName_DblClick ()
  313.  
  314.     PanelLocalName.BevelOuter = 1
  315.     PanelLocalName.Font3D = 2
  316.     SMTPStart
  317.     PanelLocalName.Font3D = 1
  318.     PanelLocalName.BevelOuter = 2
  319.     
  320. End Sub
  321.  
  322. Sub ReportProgress (sMessage As String)
  323.     ListProgress.AddItem sMessage
  324. End Sub
  325.  
  326. Sub SMTPCancel ()
  327.  
  328.     NetClient.Connect = False
  329.  
  330.     Main.MousePointer = 0
  331.     PanelLocalName.MousePointer = 2
  332.     StatusBar.MousePointer = 0
  333.  
  334.     TextUserName.Enabled = True
  335.     TextHost.Enabled = True
  336.     
  337. End Sub
  338.  
  339. Sub SMTPParse (sLine As String)
  340. Dim iReturn As Integer
  341. Dim sTemp As String
  342.  
  343.     On Error Resume Next
  344.  
  345.     iReturn = Val(Left$(sLine, 3))
  346.  
  347.     Select Case iReturn
  348.         Case 200 To 299:    ' Ok reply
  349.             Select Case SMTPState
  350.                 Case STATE_HELO:
  351.                     sLine = "HELO " & LocalHostName
  352.                     NetClient = sLine & CRLF
  353.                     ReportProgress sLine
  354.                     SMTPState = STATE_VRFY
  355.                 Case STATE_VRFY
  356.                     sLine = "VRFY <" & TextUserName & "@" & TextHost & " > "
  357.                     NetClient = sLine & CRLF
  358.                     ReportProgress sLine
  359.                     SMTPState = STATE_MAILFROM
  360.                 Case STATE_MAILFROM:
  361.                     sLine = "MAIL FROM: <postmaster" & "@" & LocalHostName & ">"
  362.                     NetClient = sLine & CRLF
  363.                     ReportProgress sLine
  364.                     SMTPState = STATE_RCPTTO
  365.                 Case STATE_RCPTTO:
  366.                     sLine = "RCPT TO: <" & TextUserName & "@" & TextHost & ">"
  367.                     NetClient = sLine & CRLF
  368.                     ReportProgress sLine
  369.                     SMTPState = STATE_DATA
  370.                 Case STATE_DATA
  371.                     sLine = "DATA"
  372.                     NetClient = sLine & CRLF
  373.                     ReportProgress sLine
  374.                     SMTPState = STATE_SENDBODY
  375.                 Case STATE_QUIT
  376.                     sLine = "QUIT"
  377.                     NetClient = sLine & CRLF
  378.                     ReportProgress sLine
  379.                     SMTPState = STATE_INACTIVE
  380.                 Case STATE_INACTIVE
  381.                     SMTPCancel
  382.                     StatusBar.Caption = "Ok."
  383.                 End Select
  384.  
  385.         Case 300 To 399:    ' Informational reply
  386.             Select Case SMTPState
  387.                 Case STATE_SENDBODY:
  388.                     sTemp = "From: <postmaster@" & LocalHostName & ">"
  389.                     ReportProgress sTemp
  390.                     sLine = sTemp & CRLF
  391.                     sTemp = "To: <" & TextUserName & "@" & TextHost & ">"
  392.                     ReportProgress sTemp
  393.                     sLine = sLine & sTemp & CRLF
  394.                     sTemp = "Subject: WSMTPC Test Message"
  395.                     ReportProgress sTemp
  396.                     sLine = sLine & sTemp & CRLF & CRLF
  397.                     sTemp = "This is a test of the SMTP client that comes with WSANET."
  398.                     ReportProgress sTemp
  399.                     sLine = sLine & sTemp & CRLF
  400.                     sTemp = "."
  401.                     ReportProgress sTemp
  402.                     sLine = sLine & sTemp & CRLF
  403.                     NetClient = sLine
  404.                     SMTPState = STATE_QUIT
  405.             End Select
  406.             
  407.         Case 500 To 599:    ' Error reply
  408.             ReportProgress "500 Error! Abort!"
  409.             Select Case SMTPState
  410.                 Case STATE_SENDBODY:
  411.                     NetClient = "." + CRLF
  412.                     ReportProgress "."
  413.                     SMTPState = STATE_QUIT
  414.                 Case Else
  415.                     NetClient = "QUIT" + CRLF
  416.                     ReportProgress "QUIT"
  417.             End Select
  418.         
  419.         Case Else
  420.                 ReportProgress "Unknown reply #" & Str$(iReturn) & "0!"
  421.     End Select
  422.     
  423. End Sub
  424.  
  425. Sub SMTPStart ()
  426.     
  427.     On Error Resume Next
  428.  
  429.     NetClient.HostName = TextHost.Text
  430.     If NetClient.HostName = "" Then
  431.         NetClient.HostAddr = TextHost.Text
  432.         If NetClient.HostAddr = "" Then
  433.             ListProgress.AddItem "Host " & TextHost.Text & " unknown."
  434.             Exit Sub
  435.         End If
  436.     End If
  437.     
  438.     NetClient.Connect = True
  439.     
  440.     ListProgress.Clear
  441.     StatusBar.Caption = "Connecting to " & TextHost.Text & " - Click this message to Abort."
  442.     
  443.     Main.MousePointer = 11
  444.     PanelLocalName.MousePointer = 12
  445.     StatusBar.MousePointer = 2
  446.  
  447.     SMTPState = STATE_HELO
  448.  
  449. End Sub
  450.  
  451. Sub StatusBar_DblClick ()
  452.  
  453.     If NetClient.Connect Then Exit Sub
  454.     
  455.     StatusBar.BevelOuter = 1
  456.     SMTPCancel
  457.     StatusBar.BevelOuter = 2
  458.  
  459.     StatusBar.Caption = "Connection Aborted."
  460.  
  461. End Sub
  462.  
  463. Sub TextHost_GotFocus ()
  464.     
  465.     PanelHost.BevelOuter = 1
  466.     TextHost.SelStart = 0
  467.     TextHost.SelLength = 128
  468.  
  469. End Sub
  470.  
  471. Sub TextHost_KeyPress (KeyAscii As Integer)
  472.  
  473.     If KeyAscii = 13 Then
  474.         
  475.         SMTPStart
  476.  
  477.         KeyAscii = 0
  478.     End If
  479.  
  480. End Sub
  481.  
  482. Sub TextHost_LostFocus ()
  483.     PanelHost.BevelOuter = 2
  484.  
  485. End Sub
  486.  
  487. Sub TextUserName_GotFocus ()
  488.     
  489.     PanelUserName.BevelOuter = 1
  490.     TextUserName.SelStart = 0
  491.     TextUserName.SelLength = 64
  492.  
  493. End Sub
  494.  
  495. Sub TextUserName_KeyPress (KeyAscii As Integer)
  496.     
  497.     If KeyAscii = 13 Then
  498.         
  499.         SMTPStart
  500.  
  501.         KeyAscii = 0
  502.     End If
  503.  
  504. End Sub
  505.  
  506. Sub TextUserName_LostFocus ()
  507.     
  508.     PanelUserName.BevelOuter = 2
  509.  
  510. End Sub
  511.  
  512.